package ys.ewp.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import ys.ewp.dao.BaseDao;
import ys.ewp.dto.UserFieldDto;
import ys.ewp.po.UserField;

@Component
public class UserFieldService extends BaseService<UserField> {
	
	@Resource(name="userFieldDao")
	private BaseDao<UserField> userFieldDao;

	@Override
	protected BaseDao<UserField> getDao() {
		// TODO Auto-generated method stub
		return userFieldDao;
	}
	
	/**
	 * @功能 根据员工ID获取用户自定义字段列表
	 * @param empId 员工ID
	 * @return 用户自定义字段列表
	 */
	public List<UserField> getUserFieldListByEmpId(Integer empId){
		Object[] params = {empId};
		List<UserField> userFieldList = this.getList("o.employee.id = ?", params, null);
		return userFieldList;
	}
	
	/**
	 * @功能 根据员工ID获取用户自定义字段DTO列表
	 * @param empId 员工ID
	 * @return 用户自定义字段DTO列表
	 */
	public List<UserFieldDto> getUserFieldDtoListByEmpId(Integer empId){
		List<UserFieldDto> userFieldDtoList = new ArrayList<UserFieldDto>();
		List<UserField> userFieldList = this.getUserFieldListByEmpId(empId);
		if(userFieldList != null){
			UserFieldDto ufd;
			for(UserField uf : userFieldList){
				String label = uf.getLabel();
				String value = uf.getValue();
				ufd = new UserFieldDto();
				ufd.setLabel(label);
				ufd.setValue(value);
				userFieldDtoList.add(ufd);
			}
			return userFieldDtoList;
		}
		return Collections.emptyList();
	}

}
